#!/usr/bin/env python3
# -*- coding:utf-8 -*-
###
# File: do_generator.py
# -----
# Description: 生成器
# -----
# Created  By: Aim 2020-01-30 15:57:07
# Modified By: Aim 2020-01-30 16:40:54
# -----
# HISTORY:
# Date      	By	Comments
# ----------	---	----------------------------------------------------------
###

# g = (x * x for x in range(10))
# print(g)

# print(next(g))
# print(next(g))
# print(next(g))

# for n in g:
#     print(n)

# 斐波拉契数列
# def fibonacci(max):
#     n, a, b = 0, 0, 1
#     while n < max:
#         yield b
#         a, b = b, a+b
#         n = n+1
#     return 'done'

# fibonacci(6)

# for n in fibonacci(6):
#     print(n)


# g = fibonacci(6)

# while True:
#     try:
#         x = next(g)
#         print('g:', x)
#     except StopIteration as e:
#         print('Generator return value:', e.value)
#         break


# def odd():
#     print('Step1')
#     yield 1
#     print('Step2')
#     yield 3
#     print('Step3')
#     yield 5

# o = odd()

# print(next(o))
# print(next(o))
# print(next(o))

# 杨辉三角

def triangles():
    L = [1]
    while True:
        yield L
        L = [1] + [L[n] + L[n+1] for n in range(len(L)-1)] + [1]

g = triangles()

n = 0
results = []
for t in triangles():
    results.append(t)
    n = n + 1
    if n == 10:
        break

for r in results:
    print(r)